<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}" @reset="()=>{this.queryParams.pageNum=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="子系统名称" name="serviceName">
            <t-input
              v-model="queryParams.serviceName"
              clearable
              placeholder="请输入子系统名称"
              style="width: 240px"
            />
          </t-form-item>
          <!--        <t-form-item label="状态" name="status">-->
          <!--          <t-select style="width: 240px" placeholder="用户状态" :options="dict.type.sys_normal_disable" v-model="queryParams.status">-->
          <!--          -->
          <!--          </t-select>-->
          <!--        </t-form-item>-->
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit">查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <div class="btn-group-inline">
      <t-button @click="dialog.header='添加子系统';dialog.serviceId=0;dialog.open_add_edit = true;" variant="outline"
                theme="primary">
        <t-icon name="add" slot="icon"/>
        新增
      </t-button>
    </div>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #isBusinessService="{row}">
        {{row.isBusinessService==='1'?'是':'否'}}
      </template>
      <template #op="{ row }">
        <t-button v-hasPermi="['system:user:edit']" @click="dialog.header='修改子系统';dialog.serviceId=row.id;dialog.open_add_edit = true;" size="small" variant="text"
                  class="t-button-link">
          <t-icon name="edit-1" slot="icon"/>
          修改
        </t-button>
        <t-button theme="danger" v-hasPermi="['system:user:remove']" @click="handleDelete(row)" size="small" variant="text"
                  class="t-button-link">
          <t-icon name="delete" slot="icon"/>
          删除
        </t-button>
        <t-button v-hasPermi="['system:user:edit']" @click="jumpMenuPage(row)"  size="small" variant="text"
                  class="t-button-link">
          <t-icon name="view-list" slot="icon"/>
          菜单
        </t-button>
      </template>
    </t-table>
    <add-edit-subsystem @reload="getList" :header="dialog.header" :serviceId="dialog.serviceId" :visible.sync="dialog.open_add_edit" v-if="dialog.open_add_edit"></add-edit-subsystem>
  </div>
</template>

<script>

import AddEditSubsystem from "./components/add-edit-subsystem.vue";

export default {
  name: "subsystem-index",
  components:{
    AddEditSubsystem
  },
  data() {
    return {
      data: [],
      columns: [
        {
          colKey: "serviceName",
          title: "子系统名称",
          align: "center"
        },
        {
          colKey: "serviceCode",
          title: "子系统code",
          align: "center"
        },
        // {
        //   colKey: "serviceRout",
        //   title: "子系统路由",
        //   align: "center"
        // },
        {
          colKey: "serviceSort",
          title: "排序号",
          align: "center"
        },
        {
          colKey: "isBusinessService",
          title: "是否可申报成果",
          align: "center"
        },
        {
          colKey: "remark",
          title: "备注",
          align: "center"
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 250
        },
      ],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serviceName: "",
        dateRange: []
      },
      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
      dialog:{
        serviceId:0,
        header:"",
        open_add_edit: false,
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.dataLoading = true;
      this.$api.system.subsystem.sysServiceList(this.queryParams).then((res) => {
        this.data = res.rows;
        this.pagination.total = res.total;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      })
    },
    jumpMenuPage(row) {
      this.$router.push({
        path:`/home/other/system/sub-system/menu/${row.id}`,
        query:{
          title: `${row.serviceName}-菜单管理`
        }
      });
    },
    jumpRolePage(serviceId) {
      this.$router.push(`/home/other/system/role/user/${serviceId}`);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除名称为"${row.serviceName}"的数据项？`,
        theme: "warning",
        onConfirm: ({e}) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.$api.system.subsystem.sysServiceDelete(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        },
      })
    }
  },

}
</script>

<style scoped>

</style>
